import { getStore } from '@/utils/store'
import { getAreaObj } from '@/utils/util'

export const formProjectConfig = (subsidyType?: string | number) => {
	return {
		inline: false,
		showBtn: false,
		labelPosition: 'top',
		labelWidth: '100px',
		column: [
			{
				label: '选择申请补贴类型',
				prop: 'subsidyType',
				propName: 'subsidyTypeLabel',
				type: 'remoteSelect',
				api: 'getDictItemList',
				code: 'SUBSIDY_TYPE',
				filterKey: 'value',
				multiple: false,
				span: 24,
				rules: [{ required: true, message: '请选择申请补贴类型' }],
			},
			{
				label: '名称',
				prop: 'subsidyApplyConfigId',
				span: 24,
				rules: [{ required: true, message: '请选择项目名称' }],
			},
			// {
			// 	label: '选择申请服务对象',
			// 	prop: 'applicateObject',
			// 	type: 'remoteSelect',
			// 	api: 'view_dpServiceObject_page',
			// 	filterKey: 'idCard',
			// 	filterLabel: 'name',
			// 	multiple: false,
			// 	span: 24,
			// 	display:  subsidyType==6,
			// 	rules: [{ required: true, message: '请选择申请服务对象' }],
			// },
			{
				label: '选择申请从业人员',
				prop: 'applicateObject',
				type: 'remoteSelect',
				api: 'view_dpFoundationPractitioners_page',
				filterKey: 'idCard',
				filterLabel: 'practitionersName',
				multiple: false,
				span: 24,
				display: subsidyType==5,
				rules: [{ required: true, message: '请选择申请从业人员' }],
			},
		],
	}
}

export const tableConfig ={
	
		stripe: true,
		border: true,
		maxHeight: '80vh',
		columns: [
			{
				label: '申请人',
				prop: 'oldmanName',
			},
			{
				label: '户籍所在区',
				prop: 'crAreaName',
			},
			{
				label: '证件号码',
				prop: 'idCard',
			},
			{
				label: '性别',
				prop: 'genderLabel',
			},
			{
				label: '年龄',
				prop: 'age',
			},
			{
				label: '联系方式',
				prop: 'oldmanPhone',
			},
			{
				label: '政府扶助对象申请时间',
				prop: 'createTime',
			},
			{
				label: '老人类型',
				prop: 'elderlyTypeLabel',
			},
			{
				label: '评估机构评估结果',
				prop: 'assessAbilityLevel',
				custome: 'tag',
				dicData:[
					{label:"自理",value:'1',type:'primary'},
					{label:"半失能",value:'2',type:'warning'},
					{label:"失能",value:'3',type:'danger'},
					{label:"失智",value:'4',type:'danger'},
				]
			},
			{
				label: '备注',
				prop: 'note',
			},
			{
				label: '操作',
				prop: 'menu',
				width: 300,
				fixed: 'right',
			},
		],
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '100px',
	column: [
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			span: 8,
		},
		{
			label: '户籍区域',
			prop: 'area_name',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			checkStrictly: false,
			span: 8,
		},
		{
			label: '姓名',
			prop: 'oldmanName',
			type: 'input',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'oldmanPhone',
			type: 'input',
			span: 8,
		},
		{
			label: '老人类型',
			prop: 'elderlyType',
			propName:"elderlyTypeLabel",
			code:"ELDERLY_TYPE",
			api:"getDictItemList",
			type: 'remoteSelect',
			span: 8,
		},
		{
			label: '评估机构评估结果',
			prop: 'assessAbilityLevel',
			clearable:true,
			dicData:[
				{label:"自理",value:1},
				{label:"半失能",value:2},
				{label:"失能",value:3},
				{label:"失智",value:4},
			],
			type: 'select',
			span: 8,
		},
		{
			label: '申请时间',
			prop: 'createTimeBetween',
			type: 'datetimerange',
			startPlaceholder:'请填写开始时间',
			endPlaceholder:'请填写结束时间',
			span: 16,
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
		},
		
	],
}


const auth = {
	index: 'view_ofsSubsidyApply_elderly_amount_page',
	add: 'view_ofsSubsidyAmountDetail_save_batch',
	delete: 'view_ofsSubsidyAmountDetail_del',
}
export const baseConfig: any = {
	pageName: '申请管理',
	addLabel: '添加',
	dictcodes: ['SUBSIDY_TYPE'],
	rowKey: 'amountDetailId',
	tipLabel: 'oldmanName',
	api: {
		index: 'view_ofsSubsidyApply_elderly_amount_page',
		add: 'view_ofsSubsidyAmountDetail_save_batch',
		delete: 'view_ofsSubsidyAmountDetail_del',
		authArea: true,
	},
	auth,
	menuBtn: [
		{
			icon: '',
			label: '查看',
			type: 'primary',
			operate: 'Detail',
			auth: auth.index,
			text: true,
			show: true,
		},
		{
			icon: '',
			label: '删除',
			type: 'primary',
			operate: 'delete',
			condition:"(row)=>row.finalApprovalStatus != 1||row.finalApprovalStatus != -1",
			auth: auth.delete,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '85%',
	},
	tableConfig,
	searchConfig,
	detailConfig:{
		customeHeader: {
			integrityConfig: {
				baseTableName: 'dp_service_object',
				materialTableName: 'dp_service_object_material',
				soleValue: 'idCard',
			},
			type: 'CardTwo',
			title: 'name',
			avatar: 'image',
			tipList: [{ prop: 'telephone', type: 'tip-success', label: '联系电话' }],
			tagList: [
				{
					prop: 'countryLevel',
					propName: 'countryLevelLabel',
					code: 'ACCESS_LEVEL_COUNTRY',
					custome: 'tag',
					type: 'success',
					label: '能力等级',
				},
				{ prop: 'birthday', type: 'success', label: '公历' },
				{ prop: 'lunarBirthday', type: 'success', label: '农历' },
			],
			menuBtn: [
				{
					icon: 'delete',
					label: '删除服务对象',
					type: 'danger',
					operate: 'delete',
					auth: 'view_dpServiceObject_del',
					hide: 'dataStatus==0',
					text: false,
					show: true,
					plain: true,
				},
			],
		},
	},
	beforeOnLoadFormate:(query)=>{
		let areaNameObj:any = {}
		if(query.area_name){
			areaNameObj = getAreaObj(query.area_name,'cr')
		}
		if(query.createTimeBetween){
			query.createTimeBetween = query.createTimeBetween.join(",")
		}
		query = {
			...query,
			...areaNameObj,
			area_name:undefined,
			authArea:undefined,
			authCity:undefined,
			authProvince:undefined,
			authStreet:undefined
		}
		return new Promise((resolve,reject)=>{
			resolve(query)
		})
	},
	onLoadFormate:(arr)=>{
		arr.forEach(el => {
			if(el.tableRel){
				el.tableRelVal = JSON.parse(el.tableRel)
				el.tableRelVal = el.tableRelVal[0].value
			}else{
				el.tableRelVal = ''
			}
		})
		return new Promise((resolve,reject)=>{
			resolve(arr)
		})
	}
}
